package com.googlecode.moneyManager.dao.hib;

import com.googlecode.moneyManager.dao.DepositDAO;
import com.googlecode.moneyManager.exceptions.DataAccessException;
import com.googlecode.moneyManager.model.Customer;
import com.googlecode.moneyManager.model.Deposit;
import org.hibernate.Session;

import java.util.List;
/**
 * 
 * @author Sergiy Doroshenko
 * Jul 20, 2008 11:54:42 PM
 */
@Deprecated
public class DepositDaoHib implements DepositDAO{
    
    private Session session = HibernateUtil.getSession();

    public String create(Deposit d) throws DataAccessException {
	session.persist(d);
	return d.getId();
    }

    public void delete(Deposit t) throws DataAccessException {
    }

    public Deposit get(String id) throws DataAccessException {
	return null;
    }
    @SuppressWarnings(value = "unchecked")
    public List<Deposit> getAll() throws DataAccessException {
	List<Deposit> l = session.createQuery("from Deposit d").list();
	return l;
    }

    public void merge(Deposit t) throws DataAccessException {
    }

    public void saveOrUpdate(Deposit d) throws DataAccessException {
	session.saveOrUpdate(d);
	
    }
    @SuppressWarnings(value = "unchecked")
    public List<Deposit> getDepositsByUser(Customer user) {
	return session.createQuery("from Deposit d where d.user = ?")
			.setEntity(0, user)
			.list();
    }

}
